package com.zzptc.zzsgz.bdsjws.activities;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.fragments.FirstFragment;
import com.zzptc.zzsgz.bdsjws.fragments.SecondFragment;

import butterknife.BindView;

public class OneKeySOSActivity extends BaseActivity {

    @BindView(R.id.toolbar_sos)
    Toolbar toolbarSos;
    @BindView(R.id.fl_sos)
    FrameLayout flSos;
    FirstFragment firstFragment;
    @BindView(R.id.img_question)
    ImageView imgQuestion;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int getContentXML() {
        return R.layout.activity_one_key_sos;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        setSupportActionBar(toolbarSos);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        //加载第一个Fragment
        if (firstFragment == null) {
            firstFragment = new FirstFragment();
        }
        getFragmentManager().beginTransaction().replace(R.id.fl_sos, firstFragment).addToBackStack("sos").commit();

    }

    //由第二个Fragment替换了第一个Fragment
    public void toSecondFragment() {

        getFragmentManager().beginTransaction().hide(firstFragment).add(R.id.fl_sos, new SecondFragment()).addToBackStack("sos").commit();
        //让question图标消失    在回退时图标再显示
        imgQuestion.setVisibility(View.GONE);
    }

    @Override
    public void onBackPressed() {
        //super.onBackPressed();
        if (getFragmentManager().getBackStackEntryCount() > 1) {
            getFragmentManager().popBackStack();
            imgQuestion.setVisibility(View.VISIBLE);
        } else {
            finish();
        }
    }
}
